Skip to content

[mlir][cmake] Fix MLIR shared library installation #152195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 7, 2025

Conversation

brnorris03
Copy link
Contributor

@brnorris03 brnorris03 commented Aug 5, 2025

When LLVM_INSTALL_TOOLCHAIN_ONLY=ON, the MLIR shared library (libMLIR*) is not installed even though it is built with the INSTALL_WITH_TOOLCHAIN argument to the add_mlir_library cmake function. This patch ensures that libMLIR* is installed when LLVM_INSTALL_TOOLCHAIN_ONLY=ON.

Patch verified here.

fixes #151247

@llvmbot llvmbot added the mlir label Aug 5, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 5, 2025

@llvm/pr-subscribers-mlir

Author: Boyana Norris (brnorris03)

Changes

When LLVM_INSTALL_TOOLCHAIN_ONLY=ON, the MLIR shared library (libMLIR*) is not installed even though it is built with the INSTALL_WITH_TOOLCHAIN argument to the add_mlir_library( cmake function. This patch ensures that libMLIR* is installed when LLVM_INSTALL_TOOLCHAIN_ONLY=ON.

Patch verified here.

Closes #151247


Full diff: https://github.com/llvm/llvm-project/pull/152195.diff

1 Files Affected:

  • (modified) mlir/cmake/modules/AddMLIR.cmake (+5-1)
diff --git a/mlir/cmake/modules/AddMLIR.cmake b/mlir/cmake/modules/AddMLIR.cmake
index ff4269ed7acd2..93b5b4766146b 100644
--- a/mlir/cmake/modules/AddMLIR.cmake
+++ b/mlir/cmake/modules/AddMLIR.cmake
@@ -388,6 +388,9 @@ function(add_mlir_library name)
 
   if(TARGET ${name})
     target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})
+    if(ARG_INSTALL_WITH_TOOLCHAIN)
+      set_target_properties(${name} PROPERTIES MLIR_INSTALL_WITH_TOOLCHAIN TRUE)
+    endif()
     if(NOT ARG_DISABLE_INSTALL)
       add_mlir_library_install(${name})
     endif()
@@ -617,7 +620,8 @@ endfunction(add_mlir_aggregate)
 # This is usually done as part of add_mlir_library but is broken out for cases
 # where non-standard library builds can be installed.
 function(add_mlir_library_install name)
-  if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
+  get_target_property(_install_with_toolchain ${name} MLIR_INSTALL_WITH_TOOLCHAIN)
+  if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR _install_with_toolchain)
   get_target_export_arg(${name} MLIR export_to_mlirtargets UMBRELLA mlir-libraries)
   install(TARGETS ${name}
     COMPONENT ${name}

@brnorris03 brnorris03 changed the title [MLIR] Fix MLIR shared library installation [mlir] Fix MLIR shared library installation Aug 5, 2025
@PHHargrove
Copy link

As the reporter of #151247, this PR has my 👍
Thanks, @brnorris03

@brnorris03 brnorris03 changed the title [mlir] Fix MLIR shared library installation [mlir][cmake] Fix MLIR shared library installation Aug 5, 2025
@brnorris03
Copy link
Contributor Author

@christopherbate, can you please take a look? I was also looking to add an install check in CI for this, but it doesn't seem like the install is being tested atm, so my own local check and the independent verification by @PHHargrove are all I have as proof that this works.

@christopherbate christopherbate merged commit 69d0bd5 into llvm:main Aug 7, 2025
9 checks passed
@ElvinaYakubova
Copy link
Contributor

Hello! This commit causes failure in our 3-stage LTO-PGO-BOLT build.
Could you suggest what changes should be made to fix it?

loading initial cache file /local/home/work/llvm-project/build-3-stage/build_Release_LTO-PGO-BOLT_main/clang/cmake/caches/PGO-stage2-instrumented.cmake
-- The C compiler identification is Clang 22.0.0
-- The CXX compiler identification is Clang 22.0.0
-- The ASM compiler identification is Clang
-- Found assembler: /local/home/work/llvm-project/build-3-stage/build_Release_LTO-PGO-BOLT_main/build/./bin/clang
-- Detecting C compiler ABI info
--...
-- Found Python3: /usr/bin/python3.11 (found suitable version "3.11.4", minimum required is "3.8") found components: Interpreter 
-- Performing Test LLVM_LIBSTDCXX_MIN
-- Performing Test LLVM_LIBSTDCXX_MIN - Success
-- Performing Test LLVM_LIBSTDCXX_SOFT_ERROR
-- Performing Test LLVM_LIBSTDCXX_SOFT_ERROR - Success
-- Looking for __GLIBC__
-- Looking for __GLIBC__ - found
 ...
-- Looking for pthread_create in pthread - found
-- Looking for pthread_rwlock_init in pthread
-- Looking for pthread_rwlock_init in pthread - found
-- Looking for pthread_mutex_lock in pthread
-- Looking for pthread_mutex_lock in pthread - found
-- Looking for dlopen in dl
-- Looking for dlopen in dl - found
-- Looking for shm_open in rt
-- Looking for shm_open in rt - found
-- Looking for pfm_initialize in pfm
-- Looking for pfm_initialize in pfm - not found
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
--...
-- Looking for __unw_add_dynamic_fde
-- Looking for __unw_add_dynamic_fde - not found
-- Looking for _Unwind_Backtrace
--
-- Looking for setenv
-- 
--
-- Performing Test HAVE_STEADY_CLOCK -- success
-- Compiling and running to test HAVE_PTHREAD_AFFINITY
-- Performing Test HAVE_PTHREAD_AFFINITY -- failed to compile
-- Configuring done
CMake Error in /local/home/work/llvm-project/build-3-stage/build_Release_LTO-PGO-BOLT_main/flang/cmake/modules/CMakeLists.txt:
  export called with target "FortranLower" which requires target
  "MLIRAffineAnalysis" that is not in any export set.

Make Error in /local/home/work/llvm-project/build-3-stage/build_Release_LTO-PGO-BOLT_main/flang/cmake/modules/CMakeLists.txt:
  export called with target "FortranLower" which requires target
  "MLIRAffineDialect" that is not in any export set.


CMake Error in /local/home/work/llvm-project/build-3-stage/build_Release_LTO-PGO-BOLT_main/flang/cmake/modules/CMakeLists.txt:
  export called with target "FortranLower" which requires target
  "MLIRAffineTransforms" that is not in any export set.


CMake Error in /local/home/work/llvm-project/build-3-stage/build_Release_LTO-PGO-BOLT_main/flang/cmake/modules/CMakeLists.txt:
  export called with target "FortranLower" which requires target
  "MLIRAffineTransformOps" that is not in any export set.


CMake Error in /local/home/work/llvm-project/build-3-stage/build_Release_LTO-PGO-BOLT_main/flang/cmake/modules/CMakeLists.txt:
  export called with target "FortranLower" which requires target
  "MLIRAffineUtils" that is not in any export set.


CMake Error in /local/home/work/llvm-project/build-3-stage/build_Release_LTO-PGO-BOLT_main/flang/cmake/modules/CMakeLists.txt:
  export called with target "FortranLower" which requires target
  "MLIRAMDGPUDialect" that is not in any export set.


CMake Error in /local/home/work/llvm-project/build-3-stage/build_Release_LTO-PGO-BOLT_main/flang/cmake/modules/CMakeLists.txt:
  export called with target "FortranLower" which requires target
  "MLIRAMDGPUTransforms" that is not in any export set.

@brnorris03
Copy link
Contributor Author

brnorris03 commented Aug 12, 2025

What configure options are you using? (Or if it's easier to answer -- how do I reproduce?)

Also, can you please check if applying this patch fixes the issue?

diff --git a/mlir/cmake/modules/AddMLIR.cmake b/mlir/cmake/modules/AddMLIR.cmake
index 14eefb50ca71..38839679ef8b 100644
--- a/mlir/cmake/modules/AddMLIR.cmake
+++ b/mlir/cmake/modules/AddMLIR.cmake
@@ -641,8 +641,8 @@ function(add_mlir_library_install name)
                               COMPONENT ${name})
     endif()
     set_property(GLOBAL APPEND PROPERTY MLIR_ALL_LIBS ${name})
-    set_property(GLOBAL APPEND PROPERTY MLIR_EXPORTS ${name})
   endif()
+  set_property(GLOBAL APPEND PROPERTY MLIR_EXPORTS ${name})
 endfunction()
 
 # Declare an mlir library which is part of the public C-API.

@ElvinaYakubova
Copy link
Contributor

We use standard 3-stage LTO-PGO-BOLT builds based on https://github.com/llvm/llvm-project/blob/main/clang/cmake/caches/BOLT-PGO.cmake.
Options we're using:

-DLLVM_ENABLE_PROJECTS=bolt;clang;flang;lld                 
-DLLVM_ENABLE_RUNTIMES=openmp;compier-rt                           
-DLLVM_TARGETS_TO_BUILD=AArch64                 
-DCLANG_DEFAULT_LINKER=lld                 
-DCMAKE_BUILD_TYPE=Release                                  
-C /local/home/work/llvm-project/llvm/../clang/cmake/caches/BOLT-PGO.cmake                 
-DBOOTSTRAP_LLVM_ENABLE_LLD=ON                 
-DBOOTSTRAP_BOOTSTRAP_LLVM_ENABLE_LLD=ON                 
-DBOOTSTRAP_CLANG_DEFAULT_LINKER=lld                 
-DBOOTSTRAP_BOOTSTRAP_CLANG_DEFAULT_LINKER=lld                 
-DPGO_INSTRUMENT_LTO=Thin   

@ElvinaYakubova
Copy link
Contributor

@brnorris03 I tried your Draft PR, it fixes the issue. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failure to install libMLIR.so when LLVM_DYLIBs and TOOLCHAIN_ONLY are enabled
5 participants